const Sequelize = require('sequelize')
module.exports = (sequelize, DataTypes) => {
  return AclUser.init(sequelize, DataTypes)
}

class AclUser extends Sequelize.Model {
  static init(sequelize, DataTypes) {
    super.init(
      {
        id: {
          autoIncrement: true,
          type: DataTypes.INTEGER,
          allowNull: false,
          primaryKey: true,
          comment: '用户id',
        },
        username: {
          type: DataTypes.STRING(20),
          allowNull: false,
          comment: '用户名',
          unique: 'username_uindex',
        },
        password: {
          type: DataTypes.STRING(32),
          allowNull: false,
          comment: '密码',
        },
        salt: {
          type: DataTypes.STRING(32),
          allowNull: false,
          defaultValue: '',
          comment: '加密盐值',
        },
        nickname: {
          type: DataTypes.STRING(40),
          allowNull: false,
          defaultValue: '',
          comment: '昵称',
        },
        email: {
          type: DataTypes.STRING(30),
          allowNull: false,
          defaultValue: '',
          comment: '邮箱',
        },
        phone: {
          type: DataTypes.STRING(15),
          allowNull: false,
          defaultValue: '',
          comment: '联系方式',
        },
        sex: {
          type: DataTypes.TINYINT,
          allowNull: false,
          defaultValue: 1,
          comment: '性别：1男2女',
        },
        age: {
          type: DataTypes.TINYINT,
          allowNull: false,
          defaultValue: 0,
          comment: '年龄',
        },
        avatar: {
          type: DataTypes.STRING(150),
          allowNull: false,
          defaultValue: '',
          comment: '头像地址',
        },
        title: {
          type: DataTypes.STRING(40),
          allowNull: false,
          defaultValue: '',
          comment: '系统名称',
        },
        expired: {
          type: DataTypes.DATE,
          allowNull: true,
          comment: '过期时间',
        },
        remark: {
          type: DataTypes.STRING(50),
          allowNull: true,
          defaultValue: '',
          comment: '备注',
        },
        status: {
          type: DataTypes.TINYINT,
          allowNull: false,
          defaultValue: 1,
          comment: '用户状态：1有效; 0冻结',
        },
        createTime: {
          type: DataTypes.DATE,
          allowNull: true,
          comment: '创建时间',
          field: 'create_time',
        },
        updateTime: {
          type: DataTypes.DATE,
          allowNull: true,
          comment: '更新时间',
          field: 'update_time',
        },
        deleteTime: {
          type: DataTypes.DATE,
          allowNull: true,
          comment: '更新时间',
          field: 'delete_time',
        },
        lastLoginTime: {
          type: DataTypes.DATE,
          allowNull: true,
          comment: '最后登录时间',
          field: 'last_login_time',
        },
      },
      {
        sequelize,
        tableName: 'acl_user',
        timestamps: true,
        underscored: true,
        paranoid: true,
        createdAt: 'createTime',
        updatedAt: 'updateTime',
        deletedAt: 'deleteTime',
        indexes: [
          {
            name: 'PRIMARY',
            unique: true,
            using: 'BTREE',
            fields: [{ name: 'id' }],
          },
          {
            name: 'username_uindex',
            unique: true,
            using: 'BTREE',
            fields: [{ name: 'username' }],
          },
        ],
      },
    )
    return AclUser
  }
}
